package com.stylefeng.guns.rest.modular.App.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.modular.App.dao.OrderCustomerRelationMapper;
import com.stylefeng.guns.rest.modular.App.model.OrderCustomerRelation;
import com.stylefeng.guns.rest.modular.App.service.IOrderCustomerRelationService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 订单乘车人关系 Service 实现 
 * @author sasazaixian
 * @Date 2018-12-25 10:45
 */
@Service
public class OrderCustomerRelationServiceImpl extends ServiceImpl<OrderCustomerRelationMapper,OrderCustomerRelation> implements IOrderCustomerRelationService {

    @Resource
    private OrderCustomerRelationMapper orderCustomerRelationMapper;

    /**
     * 删除订单乘车人关系
     * @param orderCustomerRelation
     * @return     
     */
    @Transactional
    public int deleteOrderCustomerRelation(OrderCustomerRelation orderCustomerRelation,String token)throws Exception{
        if(orderCustomerRelation==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.orderCustomerRelationMapper.deleteOrderCustomerRelation(orderCustomerRelation);
    }
    /**
     * 批量删除订单乘车人关系
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchOrderCustomerRelation(String[] ids,String token)throws Exception{
        return this.orderCustomerRelationMapper.deleteBatchOrderCustomerRelation(ids);
    }
    /**
     * 查询订单乘车人关系列表
     * @param orderCustomerRelation 订单乘车人关系对象
     * @return
     */
    public List<OrderCustomerRelation> selectListOrderCustomerRelation(OrderCustomerRelation orderCustomerRelation,String token)throws Exception{
        return  this.orderCustomerRelationMapper.selectListOrderCustomerRelation(orderCustomerRelation);
    }
    /**
	 * 分页查询订单乘车人关系列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListOrderCustomerRelation(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(orderCustomerRelationMapper.selectListOrderCustomerRelation(page,(OrderCustomerRelation)pager.getObj()));
        List<OrderCustomerRelation> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param orderCustomerRelation 订单乘车人关系对象
     * @return 
     */
    public  List<OrderCustomerRelation> selectListOrderCustomerRelationForUpdate(OrderCustomerRelation orderCustomerRelation)throws Exception{
        return  this.orderCustomerRelationMapper.selectListOrderCustomerRelationForUpdate(orderCustomerRelation);
    }
    /**
     * 通过主键id查询的订单乘车人关系列表
     * @param id 主键id
     * @return     
     */
    public  OrderCustomerRelation findOrderCustomerRelationById(String id,String token)throws Exception{
        return  this.orderCustomerRelationMapper.findOrderCustomerRelationById(id);
    }

    /**
     * 新增订单乘车人关系数据
     * @param orderCustomerRelation  订单乘车人关系对象
     * @return
     */
    @Transactional
    public int insertOrderCustomerRelation(OrderCustomerRelation orderCustomerRelation,String token) throws Exception { 
        if(orderCustomerRelation!=null && (orderCustomerRelation.getId()==null || orderCustomerRelation.getId().trim().length()<10)){
            orderCustomerRelation.setId(IdWorker.get32UUID());
        }  
        return this.orderCustomerRelationMapper.insertOrderCustomerRelation(orderCustomerRelation);
    }
    
    /**
     * 更新订单乘车人关系数据
     * @param orderCustomerRelation 订单乘车人关系对象
     * @return     
     */
    @Transactional
    public int updateOrderCustomerRelation(OrderCustomerRelation orderCustomerRelation,String token) throws Exception {     	
        return  this.orderCustomerRelationMapper.updateOrderCustomerRelation(orderCustomerRelation);
    }    

}
